/*
 ** 前端封装API接口模块 ：用户(User) 模块
 */
import http from "@/utils/request";
// 用户登录
export function loginAPI(params) {
	console.log(params);
	let {
		name,
		password
	} = params; //对象的解构赋值
	return http.request({
		url: "/user/login", //接口名， 参见接口API文档
		method: "post", //接口调用方式， 参见接口API文档
		data: {
			name,
			password
		}, //post调用接口参数传递通过data属性,参见Axios的官网
	});
}

//接口参数的传递途径
// query  body  header
//接口调用的方式
// get    post   put

// 查询用户 根据用户id
export function getDetailByIdAPI(id) {
	return http.request({
		url: "/user/detail",
		method: "get",
		params: {
			id
		},
	});
}

// 用户注册
export function registerAPI(params) {
	return http.request({
		url: "/user/register",
		method: "post",
		data: params,
	});
}

// 上传用户头像
export function uploadAvatarAPI(file) {
	console.log(file);
	let formData = new FormData();
	formData.append("avatar", file.file);
	return http.post("/upload/avatar", formData, {
		headers:{
			'Content-Type':'multipart/form-data'
		},
	});
}

//用户编辑 By 用户ID
export function updateAPI (params) {
	return http.request({
		url: "/user/update",
		method: "post",
		data: params,
	});
}

//用户编辑 By 用户ID
export function updatePwdAPI (params) {
	return http.request({
		url: "/user/updatePwd",
		method: "post",
		data: params,
	});
}
